<#import "/WEB-INF/freemarker_macro/page.ftl" as mypage>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="expires" content="0"/>
<title>产品列表</title>
<link rel="stylesheet" type="text/css" href="${base}/css/admin/global.css" />
<link rel="stylesheet" type="text/css" href="${base}/css/admin/mainframe.css" />
<script src="${base}/js/jquery-1.4.2.min.js" type="text/javascript"></script>

<script type="text/javascript">
	
function doSearch(curPage,perPage){
	$("#curPage").val(curPage);
	$("#perPage").val(perPage);
	$("#searchForm").submit();
}

//全选 
function checkAll(isChecked){
	if(isChecked){
		$("input[name='checkOne']").attr("checked",true);
	}else{
		$("input[name='checkOne']").attr("checked",false);
	}
	
}

function getCheckedProd(){
	var prod = new Array();
	$("input[name='checkOne']:checked").each(function(){
		prod.push(this.value);
	});
	return prod;
}

function del(id){
	
	if(confirm("确认删除吗？")){
		var url = "${base}/admin/prod/del.do";
		$.post(url,{id:id},function(data){
			if(data=="1"){
				doSearch();
			}else{
				_alert("删除失败!");
			}
		},"text")
	}
}

function batchDel(){
	
	var prod = getCheckedProd();
	if(prod.length==0){
		_alert("请选择要删除的商品！");
		return;
	}
	if(confirm("确认删除吗？")){
		var url = "${base}/admin/prod/batchDel.do";
		$.post(url,{ids:prod.join(",")},function(data){
			if(data=="1"){
				doSearch();
			}else{
				_alert("删除失败!");
			}
		},"text")
	}
}

//上架\下架
function isUsed(status){
	var prod = getCheckedProd();
	if(prod.length==0){
		_alert("请选择商品！");
		return;
	}
	
	var url = "${base}/admin/prod/updStatus.do";
	$.post(url,{"status":status,"ids":prod.join(",")},function(data){
		if(data=="1"){
			doSearch();
		}else{
			alert("更新失败!");
		}
	},"text")
}

</script>

	</head>
	<body>
		<DIV class="mbody">
			<div class="tagLine">
				<a href="${base}/admin/main.do" target="_self">桌面</a> » 产品管理 » 产品列表
			</div>
			<div class="toparea">
				<form id="searchForm" name="searchForm" action="${base}/admin/prod/list.do" method="post">
					<table border="0" cellpadding="0" cellspacing="0" width="100%"
						class="infotable">
						<tr>
							<td class="titletd">
								商品分类:
							</td>
							<td class="infotd">
								<select>
									<option>全部</option>
									<#if types?? && types?size gt 0 >
										<#list types as type>
											<option value="${type.typeId}">${type.typeName}</option>
										</#list>
									</#if>
								</select>
							</td>
							<td class="titletd">
								产品名称:
							</td>
							<td class="infotd">
								<input name="prdName" id="prdName" type="text" class="txts" value="${req_prdName!''}" />
							</td>
							<td class="titletd">
								产品编码:
							</td>
							<td class="infotd">
								<input name="prodCode" id="prodCode" type="text" class="txts" value="${req_prodCode!''}" />
							</td>
							<td>
								<input type="button" value="搜索"
									onclick="$('#searchForm').submit()" />
							</td>
						</tr>
					</table>
					<input type="hidden" name="curPage" id="curPage" />
					<input type="hidden" name="perPage" id="perPage" />
				</form>
			</div>
			<div class="tabledata">
				<table border="0" cellpadding="0" cellspacing="0" width="100%"
					class="listTable">
					<tr class="top">
						<td class="first">
							<input type="checkbox" name="_checkBox" id="_checkBox"
								onclick="checkAll(this.checked)" />
						</td>
						<td colspan="5">
							<span class="sysBtn"><a href="javascript:void(0)"
								onclick="isUsed('1')"><b class="icon icon_start"></b>上架</a>
							</span>
							<span class="sysBtn"><a href="javascript:void(0)"
								onclick="isUsed('2')"><b class="icon icon_stop"></b>下架</a>
							</span>
							<span class="sysBtn"><a href="javascript:batchDel()"><b
									class="icon icon_del"></b>删除</a>
							</span>
						</td>
					</tr>
					<tr class="top">
						<th class="first"></th>
						<th>
							商品名称
						</th>
						<th>
							商品编码
						</th>
						<th>
							商品分类
						</th>
						<th>
							状态
						</th>
						<th>
							管理
						</th>
					</tr>

					<#if page.list??> <#list page.list as bean> 
					<tr class="data">
						<td class="first">
							<input type="checkbox" name="checkOne" value="${bean.prodId}" />
						</td>
						<td>
							${bean.prodName!""}
						</td>
						<td>
							${bean.prodCode!""}
						</td>
						<td>
							${bean.typeName!""}
						</td>
						<td>
							<#if bean.status==1>上架
							<#elseif bean.status==2>下架
							</#if>
						</td>
						<td>
							<span class="sysBtn">
								<a href="${base}/admin/prod/toEdit.do?id=${bean.prodId}">编辑</a>
							</span>
							<span class="sysBtn">
								<a href="javascript:del('${bean.prodId}')" target="_self">删除</a>
							</span>
						</td>
					</tr>
					</#list> </#if>
				</table>
				<div class="datapages" id="pageDiv">
					<@mypage.page pageset=page link="javascript:doSearch"/>
				</div>
			</DIV>
	</body>
</html>
